#include "graphics_engine.h"

using namespace std;

void graphics_engine::frame()
{  
   Event event;
   while(mainWindow.GetEvent(event))
   {    
      switch(event.Type)
      {
         case Event::Closed:
            parent->stop();
            break;
      }
   }       

   mainWindow.Clear();//Efface l'écran
   process_queue();//Effectuent ses actions

   for(int i = 0 ; i < permanent.size() ; i++)
      mainWindow.Draw(*permanent[i]);

   mainWindow.Display();//Affiche les choses à afficher
}

void graphics_engine::process_event(engine_event& event)
{
   switch(event.type)
   {
      case DRAW_TEXT:
         draw_text(event.s_data["text"], event.i_data["font_id"], event.f_data["size"], event.pix_coord_data["pixel_coord"], Color(event.i_data["R"],event.i_data["G"],event.i_data["B"]), event.f_data["time"]);
         break;
   }
}

void graphics_engine::init_fonts()
{
   Font font_0;
   font_0.LoadFromFile("datas/fonts/Futured.TTF");
   font.push_back(font_0);
}

void graphics_engine::draw_text(string txt, int font_id, float size, Vector2<float> pixel_coord, Color color, float ms)
{
   String *d_txt = new String(txt, font[font_id], size);
   d_txt->SetColor(color);
   d_txt->SetPosition(pixel_coord);
   if(ms == INFINI) 
      permanent.push_back(d_txt);
}

graphics_engine::~graphics_engine()
{
   for(int i = 0 ; i < permanent.size() ; i++)
      delete permanent[i];
}


